// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html


import SDKManager from "../SDKManager";
import BaseManager from "./BaseManager";



const {ccclass, property} =  cc._decorator;

@ccclass
export default class navigateview extends cc.Component {

    @property(cc.Label)
    openid:cc.Label=null;

    opencallback(){
        this.fucn();
    }

    protected start(): void {

        this.fucn();
    }

    fucn(){
        if(window['tt']){
            this.node.getChildByName("beian").active=true;
            this.node.getChildByName("weibeian").active=false;
        }else if(window['ks']){

            if(SDKManager.getInstance().ks_openid != ""){
                console.log("openid已获取");
                this.openid.node.active=true;
                this.openid.string="openid:"+SDKManager.getInstance().ks_openid;
            }else{
                console.log("openid未获取");
                this.openid.node.active=false;
            }

            this.node.getChildByName("beian").getChildByName("4").active=false;
            let ks = window['ks'];
            ks.checkSliderBarIsAvailable({
                success: (result) => {
                    
                    console.log("侧边栏调用成功",result);

                    if(result.available){
                        this.node.getChildByName("beian").active=true;
                        this.node.getChildByName("weibeian").active=false;
                    }else{
                        this.node.getChildByName("beian").active=false;
                        this.node.getChildByName("weibeian").active=true;
                    }
                },
                fail: (result) => {
                    console.log("侧边栏调用失败: " ,result);
                    this.node.getChildByName("beian").active=false;
                    this.node.getChildByName("weibeian").active=true;
                },
            })  
        }else{
            this.node.getChildByName("beian").active=true;
            this.node.getChildByName("weibeian").active=false;
        }
    }

    callbackBtn (event: Event, str: string) {
        
        if (str == '4') {
            this.node.active=false;
            BaseManager.getInstance().navigateToScene();
        }

        if (str == '1') {
            this.node.active=false;
        }

        if (str == '5') {
            // if(SDKManager.getInstance().ks_openid != ""){
            //     this.openid.string="openid:"+SDKManager.getInstance().ks_openid;

            //     navigator.clipboard.writeText( this.openid.string);
            //     console.log('文本已复制到剪贴板');
            // }
            this.node.active=false;

        }
    }

}
